{include /common/header}
<script>
    var M={};
    $(function() {
        M.del = function(id){
            if (confirm('确定删除吗？')) {
                $.ajax({
                    url: '{:\mylib\Route::buildUrl('/admin/block/del')}',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        id:id
                    },
                    success:function(res){
                        if (res.code) {
                            location.reload();
                        }else{
                            alert(res.message);
                        }
                    }
                });
            }
        }
        M.refresh = function(){
            $.ajax({
                url: '{:\mylib\Route::buildUrl('/admin/block/refresh')}',
                type: 'POST',
                dataType: 'json',
                data: {
                    param1: 'value1'
                },
                success:function(res){
                    alert(res.message);
                }
            });
        }
    });
</script>
<p>
    <div class="btn-group">
      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        新增栏目 <span class="caret"></span>
      </button>
      <ul class="dropdown-menu">
        <li><a href="{:\mylib\Route::buildUrl('/admin/block/add')}?type=text">文本</a></li>
        <li><a href="{:\mylib\Route::buildUrl('/admin/block/add')}?type=editor">富文本</a></li>
        <li><a href="{:\mylib\Route::buildUrl('/admin/block/add')}?type=upload">上传</a></li>
        <li><a href="{:\mylib\Route::buildUrl('/admin/block/add')}?type=tpl">模板</a></li>
      </ul>
    </div>
    <button onclick="M.refresh()" class="btn btn-danger" type="button">刷新碎片</button>
</p>
<div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>#</th>
                <th>标题</th>
                <th>类型</th>
                <th>缓存时间</th>
                <th>调用标签</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {foreach $groups as $group=>$fields}
            <tr>
                <td colspan="7"><b>{$group}</b></td>
            </tr>
            {foreach $fields as $v}
            <tr>
                <td>{$v.id}</td>
                <td>{$v.title}</td>
                <td>{$v.type}</td>
                <td>{$v.expire}</td>
                <td>{literal}{:block('{/literal}{$v.name}{literal}')}{/literal}</td>
                <td>{$v.tips}</td>
                <td>
                    <a href="{:\mylib\Route::buildUrl('/admin/block/edit')}?id={$v.id}">编辑</a>
                    <a href="#" onclick="M.del('{$v.id}')">删除</a>
                </td>
            </tr>
            {/foreach}
            {/foreach}
        </tbody>
    </table>
</div>
{include /common/footer}